package workspace.teaweb.Logistics.controllers;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import workspace.teaweb.CRM.pojo.vo.CRMVO;
import workspace.teaweb.Logistics.mappers.WarehouseMapper;
import workspace.teaweb.Logistics.pojo.dto.WarehouseDto;
import workspace.teaweb.Logistics.pojo.dto.WarehouseDto2;
import workspace.teaweb.Logistics.pojo.entity.Warehouse;
import workspace.teaweb.Logistics.service.LogisticsService;
import workspace.teaweb.base.response.JsonResult;
import workspace.teaweb.base.response.StatusCode;

import javax.servlet.http.HttpSession;
import java.util.List;

@Validated//验证
@Slf4j
@Api(tags = "仓库管理")
@RestController
@RequestMapping("/Warehouse")
public class WarehouseController {
    @Autowired
    LogisticsService logisticsService;

    @ApiOperation( "新增仓库")
    @ApiOperationSupport(order = 10)
    @PostMapping("/insertWarehouse")
    public JsonResult insertWarehouse(@RequestBody Warehouse warehouse, @ApiIgnore HttpSession session) {
        CRMVO CRMVo = (CRMVO)session.getAttribute("CRM");
        logisticsService.insertWarehouse(warehouse,CRMVo);
        log.debug("仓库信息查询:{}",warehouse);
        return JsonResult.ok(warehouse);
    }
    @ApiOperation( "修改仓库")
    @ApiOperationSupport(order = 20)
    @PostMapping("/updateWarehouse")
    public JsonResult updateWarehouse(@RequestBody WarehouseDto2 warehouse, @ApiIgnore HttpSession session) {
        CRMVO CRMVo = (CRMVO)session.getAttribute("CRM");
        logisticsService.updateWarehouse(warehouse,CRMVo);
        log.debug("仓库信息查询:{}",warehouse);
        return JsonResult.ok(warehouse);
    }
    @ApiOperation( "查询仓库")
    @ApiOperationSupport(order = 30)
    @GetMapping("/selectAllWarehouse")
    public JsonResult selectAllWarehouse(@RequestBody WarehouseDto warehouse, @ApiIgnore HttpSession session) {
        CRMVO CRMVo = (CRMVO)session.getAttribute("CRM");
        List<Warehouse> warehousevo = logisticsService.selectAllWarehouse(warehouse,CRMVo);
        log.debug("仓库信息查询:{}",warehousevo);
        return JsonResult.ok(warehousevo);
    }
    @ApiOperation( "删除仓库")
    @ApiOperationSupport(order = 40)
    @PostMapping("/deleteWarehouseById")
    public JsonResult deleteWarehouseById(int id) {
        logisticsService.deleteWarehouseById(id);
        log.debug("仓库信息查询:{}",id);
        return JsonResult.ok(id);
    }



}
